package com.example.SocialApplication.activity.lists;

import com.example.SocialApplication.HelperFactory;
import com.example.SocialApplication.db.entity.ListThings;
import com.example.SocialApplication.db.entity.Thing;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CreateListStatic {
    private static ListThings mListThings;
    private static List<Thing> mThingList;

    private CreateListStatic() {
    }

    public static void initListThings() {
        mListThings = new ListThings();
        mThingList = new ArrayList<Thing>();
    }

    public static ListThings setToList() {
        return mListThings;
    }

    public static void insertThing(Thing thing) {
        thing.setListThings(mListThings);
//        mListThings.getThings().add(thing);
        mThingList.add(thing);
    }

    public static void removeThing(Thing thing) {
//        mListThings.getThings().remove(thing);
        mThingList.remove(thing);
    }

    public static void saveListThing() {
        try {
            HelperFactory.getHelper().getListThingsDAO().create(mListThings);
            for (Thing thing : mThingList) {
                HelperFactory.getHelper().getThingDAO().create(thing);
            }
//            HelperFactory.getHelper().getListThingsDAO().create(mListThings);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
